package com.book.iphone;

import com.book.book.domain.ApplyDO;
import com.book.book.domain.BooksDO;
import com.book.book.domain.CategoryDO;
import com.book.book.service.ApplyService;
import com.book.book.service.BookService;
import com.book.book.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 图书书库控制器
 * Created by siyuan on 2018/1/29.
 */
@Controller
@RequestMapping("/iphone")
public class bookLibController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    BookService bookService;


    /**
     * 获取图书的分类
     */
     @GetMapping("/category")
    String geBooklib(Model model){
         /**
          * 查询到图书分类
          */
         Map map = new HashMap();
         map.put("limit",10);
         map.put("offset",0);
         //  绑定图书分类头部
         List<CategoryDO> categoryDOList=categoryService.list(map);
         //传递图书分类名称
         List<List<BooksDO>> booksDOList1= new ArrayList<>();
         model.addAttribute("bookCategory",categoryDOList);
         for (int i = 0; i <categoryDOList.size() ; i++) {
           int cateid=categoryDOList.get(i).getCatId();
           Map map1=new HashMap();
           map.put("limit",10);
           map.put("offset",0);
           map.put("cateId",cateid);
           List<BooksDO> booksDOList =  bookService.list(map1);
           booksDOList1.add(booksDOList);
         }
         /**
          * 返回出分类的图书
          */
         model.addAttribute("bookList",booksDOList1);
         return "book/phone/main/stack";
     }
}
